<?php
namespace Goatherd\Content\Engine\Reader\Buffer;

use Goatherd\Content\Engine\Resource\IResource;

use Goatherd\Content\Engine\Queue\IItem;

use Goatherd\Content\Engine\Reader\IBufferedReader;

/**
 * Dummy buffer implementation.
 *
 * @category ContentEngine
 * @package Goatherd\Content\Engine\Reader
 * @subpackage Buffer
 */
class Blackhole
implements IBuffer
{
    /**
     *
     * @var IBufferedReader
     */
    protected $_reader = null;

    /**
     * (non-PHPdoc)
     * @see Goatherd\Content\Engine\Reader.IBuffer::activeReader()
     */
    public function activeReader(IBufferedReader $reader = null)
    {
        null === $reader or $this->_reader = $reader;
        return $this->_reader;
    }

    /**
     * Map item to resource id.
     * Uses $item->readerId property (if set).
     * Default identifier as fallback.
     *
     * @param IItem $item
     * @return mixed
     */
    public function getResourceIdentifier(IItem $item)
    {
        if (isset($item->readerId)) {
            $id = $item->readerId;
        } else {
            $id = $item->getIdentifier();
        }

        return $id;
    }

    /**
     * (non-PHPdoc)
     * @see Goatherd\Content\Engine\Reader.IBuffer::hasResource()
     */
    public function hasResource(IItem $item)
    {
        return false;
    }

    /**
     * (non-PHPdoc)
     * @see Goatherd\Content\Engine\Reader.IBuffer::getResource()
     */
    public function getResource(IItem $item)
    {
        return null;
    }

    /**
     * (non-PHPdoc)
     * @see Goatherd\Content\Engine\Reader.IBuffer::setResource()
     */
    public function setResource(IItem $item, IResource $data)
    {
        return true;
    }
}